package com.miyake.loveviewweb.client.viewer;

import com.google.gwt.user.client.ui.Composite;
import com.miyake.loveviewweb.client.DataServiceWrapper;
import com.miyake.loveviewweb.client.dialog.BasicDialog;
import com.miyake.loveviewweb.client.dialog.IDialogCreator;
import com.miyake.loveviewweb.client.dialog.TextDialog;

public class FolderDialogCreator implements IDialogCreator{
    private DataServiceWrapper serviceWrapper = DataServiceWrapper.getInstance();
    private FolderType folderType;
    
    public enum FolderType{
        ROOT_FOLDER,
        SUB_FOLDER
    }
    public FolderDialogCreator(FolderType folderType) {
        this.folderType = folderType;
    }

    public void show(String defaultName) {
        new BasicDialog(new TextDialog(defaultName)) {

            @Override
            protected void onOK(Composite composite) {
                String name = ((TextDialog)composite).getText();
                if (folderType.equals(FolderType.ROOT_FOLDER)) {
                    serviceWrapper.createRootFolder(name);
                }
                else {
                    serviceWrapper.createFolder(name, serviceWrapper.getSelectedFolder().getKey());
                }
            }
        }.showDialog();
    }
}
